package com.github.sbb.sherry.primitives.config.datasource;

import com.github.sbb.sherry.common.annotations.NotNull;
import com.github.sbb.sherry.common.base.Preconditions;
import com.github.sbb.sherry.common.base.ValidateResult;

/**
 * MySQl 数据源配置
 */
public class MySQLDataSourceConfig implements DataSourceConfig {

  private String host;
  private int port;
  private String database;
  private String username;
  private String password;
  private int minimumIdle = 5;
  private int maximumPoolSize = 5;

  @Override
  public @NotNull
  ValidateResult validate() {
    try {
      Preconditions.checkNotNull(host, "host 不能为空");
      Preconditions.checkRange(port, 1, 65535, "post 应该在 1 到 65535 之间");
      Preconditions.checkNotNull(database, "database 不能为空");
      Preconditions.checkNotNull(username, "username 不能为空");
      Preconditions.checkNotNull(password, "password 不能为空");
      Preconditions.checkRange(minimumIdle, 1, 100, "minimumIdle 建议在 1 - 100");
      Preconditions.checkRange(maximumPoolSize, 1, 100, "maximumPoolSize 建议在 1 - 100");
      Preconditions.checkRange(maximumPoolSize, minimumIdle, 100, "maximumPoolSize 应该不小于 minimumIdle");
    } catch (Exception e) {
      return new ValidateResult(false, e.getMessage());
    }
    return new ValidateResult(true, null);
  }

  public String getHost() {
    return host;
  }

  public void setHost(String host) {
    this.host = host;
  }

  public int getPort() {
    return port;
  }

  public void setPort(int port) {
    this.port = port;
  }

  public String getDatabase() {
    return database;
  }

  public void setDatabase(String database) {
    this.database = database;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public int getMinimumIdle() {
    return minimumIdle;
  }

  public void setMinimumIdle(int minimumIdle) {
    this.minimumIdle = minimumIdle;
  }

  public int getMaximumPoolSize() {
    return maximumPoolSize;
  }

  public void setMaximumPoolSize(int maximumPoolSize) {
    this.maximumPoolSize = maximumPoolSize;
  }
}
